package com.bingxue.edu.management.education.controller;

import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.common.model.SortQuery;
import com.bingxue.edu.framework.mybatis.query.QueryBuilder;
import com.bingxue.edu.framework.security.ApiResource;
import com.bingxue.edu.management.education.model.query.ClassTypeQuery;
import com.bingxue.edu.management.education.model.req.ClassTypeCreateReq;
import com.bingxue.edu.management.education.model.req.ClassTypeUpdateReq;
import com.bingxue.edu.management.education.model.resp.ClassTypeResp;
import com.bingxue.edu.management.education.service.ClassTypeService;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.bingxue.edu.management.education.model.entity.table.ClassTypeTableDef.CLASS_TYPE;

@Slf4j
@Tag(name = "班级类型接口")
@RestController
@RequestMapping("/education/class-type")
@RequiredArgsConstructor
public class ClassTypeController {

    private final ClassTypeService classTypeService;

    @Operation(summary = "查询班级类型列表" , description = "查询班级类型列表")
//    @ApiResource("system:biz-info:manage")
    @GetMapping("/list")
    public Response<List<ClassTypeResp>> classTypeList(ClassTypeQuery query, SortQuery sortQuery) {
        QueryWrapper queryWrapper = QueryBuilder.build(query, sortQuery).orderBy(CLASS_TYPE.LEVEL, true);
        List<ClassTypeResp> classTypeRespList = classTypeService.listAs(queryWrapper, ClassTypeResp.class);
        return Response.success(classTypeRespList);
    }

    @Operation(summary = "新增班级类型" , description = "新增班级类型")
    @ApiResource("system:biz-info:manage")
    @PostMapping("/create")
    public Response<Void> createClassType(@Validated @RequestBody ClassTypeCreateReq req) {
        classTypeService.create(req);
        return Response.success();
    }

    @Operation(summary = "删除班级类型" , description = "删除班级类型")
    @ApiResource("system:biz-info:manage")
    @PostMapping("/delete/{ids}")
    public Response<Void> deleteClassType(@PathVariable List<String> ids) {
        classTypeService.delete(ids);
        return Response.success();
    }

    @Operation(summary = "查询班级类型" , description = "查询班级类型")
//    @ApiResource("system:biz-info:manage")
    @GetMapping("/detail/{id}")
    public Response<ClassTypeResp> classTypeDetail(@PathVariable String id) {
        ClassTypeResp classTypeResp = classTypeService.getDetail(id);
        return Response.success(classTypeResp);
    }

    @Operation(summary = "修改班级类型" , description = "修改班级类型")
    @ApiResource("system:biz-info:manage")
    @PostMapping("/update/{id}")
    public Response<Void> updateClassType(@PathVariable String id,@RequestBody ClassTypeUpdateReq req) {
        classTypeService.update(id,req);
        return Response.success();
    }

}
